/*     */ package change.org.eclipse.swt.browser;
/*     */ 
/*     */ import org.eclipse.swt.SWT;
/*     */ import org.eclipse.swt.widgets.MessageBox;
/*     */ import org.mozilla.interfaces.nsIDOMWindow;
/*     */ import org.mozilla.interfaces.nsIEmbeddingSiteWindow;
/*     */ import org.mozilla.interfaces.nsIPromptService;
/*     */ import org.mozilla.interfaces.nsIServiceManager;
/*     */ import org.mozilla.interfaces.nsISupports;
/*     */ import org.mozilla.interfaces.nsIWebBrowserChrome;
/*     */ import org.mozilla.interfaces.nsIWindowWatcher;
/*     */ import org.mozilla.xpcom.Mozilla;
/*     */ 
/*     */ class MozillaPromptService
/*     */   implements nsIPromptService
/*     */ {
/*     */   public nsISupports queryInterface(String aIID)
/*     */   {
/*  24 */     return Mozilla.queryInterface(this, aIID);
/*     */   }
/*     */ 
/*     */   MozillaBrowser getBrowser(nsIDOMWindow aDOMWindow) {
/*  28 */     nsIServiceManager serviceManager = Mozilla.getInstance().getServiceManager();
/*  29 */     nsIWindowWatcher windowWatcher = (nsIWindowWatcher)serviceManager.getServiceByContractID("@mozilla.org/embedcomp/window-watcher;1", "{002286a8-494b-43b3-8ddd-49e3fc50622b}");
/*  30 */     nsIWebBrowserChrome webBrowserChrome = windowWatcher.getChromeForWindow(aDOMWindow);
/*  31 */     nsIEmbeddingSiteWindow embeddingSiteWindow = (nsIEmbeddingSiteWindow)webBrowserChrome.queryInterface("{3e5432cd-9568-4bd1-8cbe-d50aba110743}");
/*  32 */     long siteWin = embeddingSiteWindow.getSiteWindow();
/*  33 */     return MozillaBrowser.findBrowser(siteWin);
/*     */   }
/*     */ 
/*     */   String getLabel(long buttonFlag, long index, String buttonTitle) {
/*  37 */     String label = null;
/*  38 */     long flag = (buttonFlag & 255L * index) / index;
/*  39 */     if (flag == 2L)
/*  40 */       label = SWT.getMessage("SWT_Cancel");
/*  41 */     else if (flag == 4L)
/*  42 */       label = SWT.getMessage("SWT_No");
/*  43 */     else if (flag == 1L)
/*  44 */       label = SWT.getMessage("SWT_OK");
/*  45 */     else if (flag == 5L)
/*  46 */       label = SWT.getMessage("SWT_Save");
/*  47 */     else if (flag == 3L)
/*  48 */       label = SWT.getMessage("SWT_Yes");
/*  49 */     else if (flag == 127L) {
/*  50 */       label = buttonTitle;
/*     */     }
/*  52 */     return label;
/*     */   }
/*     */ 
/*     */   public void alert(nsIDOMWindow parent, String dialogTitle, String text)
/*     */   {
/*  58 */     MozillaBrowser browser = getBrowser(parent);
/*     */ 
/*  60 */     MessageBox messageBox = new MessageBox(browser.getShell(), 32);
/*  61 */     messageBox.setText(dialogTitle);
/*  62 */     messageBox.setMessage(text);
/*  63 */     messageBox.open();
/*     */   }
/*     */ 
/*     */   public void alertCheck(nsIDOMWindow parent, String dialogTitle, String text, String checkMsg, boolean[] checkValue) {
/*  67 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public boolean confirm(nsIDOMWindow parent, String dialogTitle, String text) {
/*  71 */     MozillaBrowser browser = getBrowser(parent);
/*     */ 
/*  73 */     MessageBox messageBox = new MessageBox(browser.getShell(), 288);
/*  74 */     messageBox.setText(dialogTitle);
/*  75 */     messageBox.setMessage(text);
/*  76 */     int id = messageBox.open();
/*     */ 
/*  79 */     return (id != 32);
/*     */   }
/*     */ 
/*     */   public boolean confirmCheck(nsIDOMWindow parent, String dialogTitle, String text, String checkMsg, boolean[] checkValue)
/*     */   {
/*  84 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public int confirmEx(nsIDOMWindow parent, String dialogTitle, String text, long buttonFlags, String button0Title, String button1Title, String button2Title, String checkMsg, boolean[] checkValue) {
/*  88 */     MozillaBrowser browser = getBrowser(parent);
/*     */ 
/*  90 */     String button1Label = getLabel(buttonFlags, 1L, button0Title);
/*  91 */     String button2Label = getLabel(buttonFlags, 256L, button0Title);
/*  92 */     String button3Label = getLabel(buttonFlags, 65536L, button0Title);
/*     */ 
/*  94 */     MozillaPromptDialog dialog = new MozillaPromptDialog(browser.getShell());
/*  95 */     int[] check = new int[1]; int[] result = new int[1];
/*  96 */     check[0] = ((checkValue[0] != false) ? 1 : 0);
/*  97 */     dialog.confirmEx(dialogTitle, text, checkMsg, button1Label, button2Label, button3Label, check, result);
/*  98 */     if (check[0] == 0)
/*  99 */       checkValue[0] = false;
/*     */     else
/* 101 */       checkValue[0] = true;
/* 102 */     return result[0];
/*     */   }
/*     */ 
/*     */   public boolean prompt(nsIDOMWindow parent, String dialogTitle, String text, String[] value, String checkMsg, boolean[] checkValue) {
/* 106 */     MozillaBrowser browser = getBrowser(parent);
/*     */ 
/* 108 */     MozillaPromptDialog dialog = new MozillaPromptDialog(browser.getShell());
/* 109 */     int[] check = new int[1]; int[] result = new int[1];
/* 110 */     if (checkValue[0] != false)
/* 111 */       check[0] = 1;
/*     */     else
/* 113 */       check[0] = 0;
/* 114 */     dialog.prompt(dialogTitle, text, checkMsg, value, check, result);
/*     */ 
/* 116 */     if (check[0] == 0)
/* 117 */       checkValue[0] = false;
/*     */     else
/* 119 */       checkValue[0] = true;
/* 120 */     return (result[0] == 0);
/*     */   }
/*     */ 
/*     */   public boolean promptUsernameAndPassword(nsIDOMWindow parent, String dialogTitle, String text, String[] username, String[] password, String checkMsg, boolean[] checkValue) {
/* 124 */     MozillaBrowser browser = getBrowser(parent);
/*     */ 
/* 126 */     if (dialogTitle.length() == 0) {
/* 127 */       dialogTitle = SWT.getMessage("SWT_Prompt");
/*     */     }
/*     */ 
/* 130 */     MozillaPromptDialog dialog = new MozillaPromptDialog(browser.getShell());
/* 131 */     int[] check = new int[1]; int[] result = new int[1];
/* 132 */     if (checkValue[0] != false)
/* 133 */       check[0] = 1;
/*     */     else
/* 135 */       check[0] = 0;
/* 136 */     dialog.promptUsernameAndPassword(dialogTitle, text, checkMsg, username, password, check, result);
/*     */ 
/* 138 */     if (check[0] == 0)
/* 139 */       checkValue[0] = false;
/*     */     else
/* 141 */       checkValue[0] = true;
/* 142 */     return (result[0] == 0);
/*     */   }
/*     */ 
/*     */   public boolean promptPassword(nsIDOMWindow parent, String dialogTitle, String text, String[] password, String checkMsg, boolean[] checkValue) {
/* 146 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public boolean select(nsIDOMWindow parent, String dialogTitle, String text, long count, String[] selectList, int[] outSelection) {
/* 150 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ }
